using Perfect.Marshal;
using System.Xml;

namespace editor
{
namespace cfg.map
{
[System.Serializable]
public  class Instance : SceneMap
 {

    public string name  = "";
     public string des  = "";
     public cfg.map.EInstanceType type ;
     


    public const int TYPE_ID = 524679761;

    public override int GetTypeId() {
        return TYPE_ID;
    }


    public override void MarshalCompatible(Perfect.Marshal.Octets os) {
        os.WriteSize(8);
        os.WriteSize(Tag.INT | (1 << Tag.TAG_SHIFT));  os.WriteInt(id);  
         os.WriteSize(Tag.BEAN | (2 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector3(initPosition,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.BEAN | (3 << Tag.TAG_SHIFT));  { var _oldOs = os; os = new Perfect.Marshal.Octets(); cfg.Extensions.marshal_compatible_cfg_map_Vector3(initDirection,os);  _oldOs.WriteOctets(os); os = _oldOs;}  
         os.WriteSize(Tag.STRING | (4 << Tag.TAG_SHIFT));  os.WriteString(assetId);  
         os.WriteSize(Tag.INT | (5 << Tag.TAG_SHIFT));  os.WriteInt(levelId);  
         os.WriteSize(Tag.STRING | (6 << Tag.TAG_SHIFT));  os.WriteString(name);  
         os.WriteSize(Tag.STRING | (7 << Tag.TAG_SHIFT));  os.WriteString(des);  
         os.WriteSize(Tag.INT | (8 << Tag.TAG_SHIFT));  os.WriteInt((int)type);  
         
    }

    public override void UnmarshalCompatible(Perfect.Marshal.Octets os) {
        for (int _var_num_ = os.ReadSize(); _var_num_-- > 0; ) {
            int _id_ = os.ReadSize();
            switch (_id_)
            {
            case (Tag.INT | (1 << Tag.TAG_SHIFT)):   id = os.ReadInt(); break;  
             case (Tag.BEAN | (2 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); initPosition = cfg.Extensions.unmarshal_compatible_cfg_map_Vector3(os); os = _oldOs; break; }   
             case (Tag.BEAN | (3 << Tag.TAG_SHIFT)):  { var _oldOs = os; os = os.ReadOctets(); initDirection = cfg.Extensions.unmarshal_compatible_cfg_map_Vector3(os); os = _oldOs; break; }   
             case (Tag.STRING | (4 << Tag.TAG_SHIFT)):   assetId = os.ReadString(); break;  
             case (Tag.INT | (5 << Tag.TAG_SHIFT)):   levelId = os.ReadInt(); break;  
             case (Tag.STRING | (6 << Tag.TAG_SHIFT)):   name = os.ReadString(); break;  
             case (Tag.STRING | (7 << Tag.TAG_SHIFT)):   des = os.ReadString(); break;  
             case (Tag.INT | (8 << Tag.TAG_SHIFT)):   type = (cfg.map.EInstanceType)(os.ReadInt()); break;  
             
            default: Tag.SkipUnknownField(_id_, os); break;
            }
         }
    }
    public override void MarshalXml(XmlWriter ele)
    {
        ele.WriteAttributeString("type", "Instance");
        ele.WriteStartElement("id"); ele.WriteAttributeString("id", "1"); ele.WriteInt(id); ele.WriteEndElement();
         ele.WriteStartElement("initPosition"); ele.WriteAttributeString("id", "2"); cfg.Extensions.xml_marshal_cfg_map_Vector3(initPosition,ele); ele.WriteEndElement();
         ele.WriteStartElement("initDirection"); ele.WriteAttributeString("id", "3"); cfg.Extensions.xml_marshal_cfg_map_Vector3(initDirection,ele); ele.WriteEndElement();
         ele.WriteStartElement("assetId"); ele.WriteAttributeString("id", "4"); ele.WriteString2(assetId); ele.WriteEndElement();
         ele.WriteStartElement("levelId"); ele.WriteAttributeString("id", "5"); ele.WriteInt(levelId); ele.WriteEndElement();
         ele.WriteStartElement("name"); ele.WriteAttributeString("id", "6"); ele.WriteString2(name); ele.WriteEndElement();
         ele.WriteStartElement("des"); ele.WriteAttributeString("id", "7"); ele.WriteString2(des); ele.WriteEndElement();
         ele.WriteStartElement("type"); ele.WriteAttributeString("id", "8"); ele.WriteEnum(type); ele.WriteEndElement();
         
    }

    public override void UnmarshalXml(XmlElement ele)
    {
        foreach (XmlElement e in ele.GetChildren())
        {
            if (int.TryParse(ele.GetAttribute("id"), out var _id_))
            {
                switch (_id_)
                {
                case 1:  id = ele.ReadInt(); break; 
                 case 2:  initPosition = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case 3:  initDirection = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case 4:  assetId = ele.ReadString2(); break; 
                 case 5:  levelId = ele.ReadInt(); break; 
                 case 6:  name = ele.ReadString2(); break; 
                 case 7:  des = ele.ReadString2(); break; 
                 case 8:  type = ele.ReadEnum<cfg.map.EInstanceType>(); break; 
                 
                default: break;
                }
            }
            else
            {
                switch (e.Name)
                {
                case "id":  id = ele.ReadInt(); break; 
                 case "init_position":  initPosition = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case "init_direction":  initDirection = cfg.Extensions.xml_unmarshal_cfg_map_Vector3(ele); break; 
                 case "asset_id":  assetId = ele.ReadString2(); break; 
                 case "level_id":  levelId = ele.ReadInt(); break; 
                 case "name":  name = ele.ReadString2(); break; 
                 case "des":  des = ele.ReadString2(); break; 
                 case "type":  type = ele.ReadEnum<cfg.map.EInstanceType>(); break; 
                 
                default: break;
                }
            }
        }
    }
}
}
}
